package com.zcl.Thread.t13;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Description:
 * @author: zcl
 * @date: 2022/3/9  13:45
 */
public class MyThread extends Thread{

    @Override
    public void run(){
        super.run();
        try {
            for (int i = 0; i < 500000; i++) {
                if (this.isInterrupted()) {
                    System.out.println("已经是停止状态了,即将退出");
                    throw new InterruptedException();
                }

                System.out.println("i = "+ (i+1));
            }
            System.out.println("我在for下面");
        } catch (InterruptedException e) {
            System.out.println("进入run方法中的catch");
            e.printStackTrace();
        }
    }
}


class Run {
    public static void main(String[] args) {
//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor();
        try {
            MyThread myThread = new MyThread();
            myThread.start();
            Thread.sleep(2000);
            myThread.interrupt();

        } catch (InterruptedException e) {
            System.out.println("main catch!");
            e.printStackTrace();
        }
        System.out.println("end");
    }
}